<?php

class ModelFactory
{
	function __construct($classname)
	{
		$this->classname = $classname;
	}
	
	function get_by_query($query)
	{
		$models=array();
		$db=database();
		$query_result=$db->get_all($query);
		
		require_once('classes/models/' . strtolower($this->classname) . '.php');
		$class = new ReflectionClass($this->classname);
		foreach($query_result as $row)
		{
			$model = $class->newInstance();
			$model->set_values($row);
			$models[] = $model;
		}
		
		return $models;
	}
}
?>